package mini.reanimate;

import owg.util.euclidian.Compass;
import world.Sound;
import hubol.ClickableRectangle;
import hubol.Sprite;

public class Left extends Screen{
	private final Money MONEY = new Money(10, 91, 86, 64);
	private final ClickableRectangle SAND = new ClickableRectangle(99, 352, 210, 60);
	private final ClickableRectangle STICKUP = new ClickableRectangle(567, 239, 88, 99);
	private final ClickableRectangle RIGHT = new ClickableRectangle(729, 39, 127, 412);
	
	private final float SCALE = 1.025f;
	private int shakeCounter = 0;

	public Left() {
		super(15, "left", "stickup", "petals");
		sprite[2].setOrigin(Compass.NORTHWEST);
	}
	
	public Money poop(){
		return MONEY;
	}

	@Override
	public void step() {
		MONEY.step();
		
		if (!busy()){
			if (!Reanimate.me.gotMoney){
				if (MONEY.moused()){
					Reanimate.me.setMouse(2);
					if (MONEY.clicked()){
						Reanimate.me.money = true;
						Reanimate.me.gotMoney = true;
						Reanimate.me.point(Reanimate.me.pMoney);
						
						new Spam("get", 5);
						Sound.playPitched("moneyget");
						//TODO 3-second song
						Reanimate.me.BOGUS.dance(180);
					}
				}
			}
			if (!busy()){
				if (!Reanimate.me.gotStick){
					if (STICKUP.moused()){
						Reanimate.me.setMouse(2);
						if (STICKUP.clicked()){
							Reanimate.me.stick = true;
							Reanimate.me.gotStick = true;
							Reanimate.me.point(Reanimate.me.pStick);
							
							new Spam("get", 5);
							Sound.playPitched("petalget");
							Reanimate.me.BOGUS.jump();
						}
					}
				}
			}
			if (!busy()){
				if (Reanimate.me.gotStick && Reanimate.me.stick){
					if (SAND.moused()){
						Reanimate.me.setMouse(Reanimate.me.sStick);
						if (SAND.clicked()){
							
							new Spam("use", 5);
							Reanimate.me.setLevel(Reanimate.me.WRITING);
						}
					}
				}
			}
			if (!busy()){
				if (Reanimate.me.petalsPlaced >= 3 && Reanimate.me.flame){
					if (SAND.moused()){
						Reanimate.me.setMouse(Reanimate.me.sFlame);
						if (SAND.clicked()){
							
							new Spam("use", 5);
							Reanimate.me.on(1);
							Reanimate.me.on(2);
							
							Reanimate.me.setLevel(Reanimate.me.FLAME);
							//TODO end
						}
					}
				}
			}
			if (!busy()){
				if (Reanimate.me.written && Reanimate.me.petals > 0){
					if (SAND.moused()){
						Reanimate.me.setMouse(Reanimate.me.sPetals);
						if (SAND.clicked()){
							Sound.playPitched("petalplace");
							new Spam("use", 5);
							
							Reanimate.me.petals--;
							Reanimate.me.petalsPlaced++;
						}
					}
				}
			}
			if (!busy()){
				if (RIGHT.moused()){
					Reanimate.me.setMouse(0);
					if (RIGHT.clicked()){
						Reanimate.me.BOGUS.right();
					}
				}
			}
		}
	}

	@Override
	public void enter() {
		if (Reanimate.me.flame)
			Reanimate.me.on(5);
	}

	@Override
	public void leave() {
		Reanimate.me.off(5);
	}
	
	public void scene(Sprite sprite, int img, double x, double y){
		sprite.render(img, x + s[shakeCounter].x, y + s[shakeCounter].y, SCALE, SCALE, 0);
		shakeCounter++;
	}
	
	public void scene(Sprite sprite, int img){
		scene(sprite, img, 432, 243);
	}
	
	public void scene(int img){
		scene(sprite[0], img);
	}

	@Override
	public boolean background() {
		shakeCounter = 0;
		
		scene(0);
		scene(1);
		if (!Reanimate.me.gotMoney)
			MONEY.render(s[shakeCounter]);
		scene(2);
		scene(3);
		if (Reanimate.me.written){
			scene(5);
			scene(sprite[1], 0, 432-292, 243+18);
		}
		else if (!Reanimate.me.gotStick)
			scene(sprite[1], 0);
		for (int i=0; i<Reanimate.me.petalsPlaced; i++)
			scene(sprite[2], i, 0, 0);
		
		return true;
	}

	@Override
	public void foreground() {
		scene(4);
	}

	@Override
	public void bogusLand() {
		// TODO Auto-generated method stub
		
	}

}
